<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="copyright" content="All Rights Reserved, Copyright (C) 2013, Wuyeguo, Ltd."/>
    <title>智能应急快速搭建平台V1.0</title>
    <script type="text/javascript" src="../../js/commonCss.js"></script>
    <script type="text/javascript" src="../../js/commonJs.js"></script>
</head>
<div class="easyui-layout" data-options="fit:true">
    <!-- Begin of toolbar -->
    <div id="wu-toolbar-form">
        <div class="wu-toolbar-button">
            <a href="#" class="easyui-linkbutton" iconCls="icon-add" onclick="openAdd()" plain="true">添加</a>
<!--            <a href="#" class="easyui-linkbutton" iconCls="icon-edit" onclick="openEdit()" plain="true">修改</a>-->
            <a href="#" class="easyui-linkbutton" iconCls="icon-remove" onclick="remove()" plain="true">删除</a>
        </div>
        <div class="wu-toolbar-search">
            <label>表单名称：</label><input id="search_userName" name="search_userName" class="wu-text" style="width:100px">
            <a href="#" class="easyui-linkbutton" iconCls="icon-search" onclick="doSearch()">开始检索</a>
        </div>
    </div>
    <!-- End of toolbar -->
    <table id="form-datagrid" class="easyui-datagrid" toolbar="#wu-toolbar-2"></table>
</div>
<!-- Begin of easyui-dialog -->
<div id="psys-dialog" class="easyui-dialog" data-options="closed:true,iconCls:'icon-save'"
     style="width:400px; padding:10px;">
    <form id="psys-form" method="post">
        <input type="hidden" name="uuid" id="uuid">
        <table>
            <tr>
                <td width="60" align="right">表单名称:</td>
                <td><input type="text" name="formName" id="formName" class="wu-text"/></td>
            </tr>
            <tr>
                <td width="60" align="right">表单ID:</td>
                <td><input type="text" name="formId" id="formId" class="wu-text"/></td>
            </tr>
            <tr>
                <td width="60" align="right">表单版本号:</td>
                <td><input type="text" name="version" id="version" class="wu-text"/></td>

            </tr>
            <tr>
                <td width="60" align="right">表单内容:</td>
                <td><textarea id="content" name="content" rows="6" class="wu-textarea" style="width:260px"></textarea></td>
            </tr>
        </table>
    </form>
</div>
<!-- End of easyui-dialog -->
<script type="text/javascript">
    $(function() {
        $("#userName,#useSysName").validatebox({
            required:true
        });
    });
    /**
     * Name 查询
     */
    function doSearch() {
        $('#form-datagrid').datagrid('load', {paramData: JSON.stringify(searchData())});
    }


    /**
     * Name 添加记录
     */
    function add() {
        save("/user/add");
    }

    /**
     * Name 修改记录
     */
    function edit() {
        save("/user/update");
    }

    /**
     * Name 删除记录
     */
    function remove() {
        $.messager.confirm('信息提示', '确定要删除该记录？', function (result) {
            if (result) {
                var items = $('#form-datagrid').datagrid('getSelections');
                var ids = [];
                $(items).each(function () {
                    ids.push(this.userId);
                });
                //alert(ids);return;
                $.ajax({
                    url: '/user/del',
                    data: 'ids=' + ids,
                    success: function (data) {
                        if (data) {
                            $.messager.alert('信息提示', '删除成功！', 'info');
                            $('#form-datagrid').datagrid();
                        } else {
                            $.messager.alert('信息提示', '删除失败！', 'info');
                        }
                    }
                });
            }
        });
    }

    /**
     * Name 打开添加窗口
     */
    function openAdd() {
       window.open("/vue-form/dist/index.html");
    }

    /**
     * Name 打开修改窗口
     */
    function openEdit(id) {
        window.open("/vue-form/dist/index.html?form_id="+id);
        // $('#psys-form').form('clear');
        // var jsonArray = [];
        // if (id != null && id != "") {
        //     var obj = {'column': "uuid", 'type': 'eq', "value": id};
        //     jsonArray.push(obj)
        // }
        // $.ajax({
        //     type: 'POST',
        //     url: '/form-info/find',
        //     dataType: 'json',
        //     data: {paramData: JSON.stringify(jsonArray)},
        //     success: function (data) {
        //         //alert(data.data.toString());
        //         $('#psys-form').form('load', data.data)
        //     }
        // })
        // $('#psys-dialog').dialog({
        //     closed: false,
        //     modal: true,
        //     title: "修改信息",
        //     buttons: [{
        //         text: '确定',
        //         iconCls: 'icon-ok',
        //         handler: edit
        //     }, {
        //         text: '取消',
        //         iconCls: 'icon-cancel',
        //         handler: function () {
        //             $('#psys-dialog').dialog('close');
        //         }
        //     }]
        // });
    }

    /**
     * Name 载入数据
     */
    $('#form-datagrid').datagrid({
        url: '/form-info/all',
     //   loadFilter: pagerFilter,
        //idField:"id",
        rownumbers: true,
      //  singleSelect: false,
        pageSize: 20,
        pagination: true,
      //  multiSort: true,
        fitColumns: true,
        //如果为true，该复选框被选中/取消选中，当用户点击某一行上。如果为false，该复选框仅检查/取消选中，当用户点击完全的复选框。
        checkOnSelect:false,
        fit: true,
        pageList: [10, 20, 50, 100, 150, 200],
        columns: [[
            {checkbox: true},
            {field: 'uuid', title: 'uuid', width: 100, sortable: true, align: 'center', hidden: 'true'},
            {
                field: 'formName',
                title: '表单名称',
                width: 180,
                sortable: true,
                align: 'center',
                formatter: function (value, data) {
                    return '<a style="color: blue;" href="javascript:openEdit(\''+data.uuid+'\')">' + data.formName + '</a>';
                }
            },
            {field: 'formId', title: '表单ID', width: 100, align: 'center'},
            {field: 'version', title: '版本号', width: 100, align: 'center'},
            {field: 'createTime', title: '创建时间', width: 100, align: 'center'}

        ]]
    });

    function searchData() {
        var userName = $("#search_userName").val();
        var jsonArray = [];
        if (userName != null && userName != "") {
            var obj = {'column': "form_name", 'type': 'like', "value": userName};
            jsonArray.push(obj)
        }
        return jsonArray;
    }


    function save(url) {
        var t = $('#showId').combotree('tree');	// get the tree object
        var n = t.tree('getSelected');		// get selected node
        //  alert(n.id);
        $("#deptId").val(n.id);
        var formObject = {};
        var formArray = $("#psys-form").serializeArray();
        $.each(formArray, function (i, item) {
            formObject[item.name] = item.value;
        });
        // alert(JSON.stringify(formObject));
        $.ajax({
            url: url,
            type: "post",
            contentType: "application/json; charset=utf-8",
            data: JSON.stringify(formObject),
            dataType: "json",
            success: function (data) {
                $.messager.alert('信息提示', '提交成功！', 'info');
                $('#psys-dialog').dialog('close');
                $('#form-datagrid').datagrid('reload');
            },
            error: function () {
                $.messager.alert('信息提示', '提交失败！', 'info');
            },

        });
    }
</script>